#pragma once
#include "TcpServer.hpp"

class Connection;
class TcpServer;

using func_t =function< void(std::weak_ptr<Connection>) >;
using except_fun =function<void(std::weak_ptr<Connection>)>;

class Connection
{
public:
    Connection(int sock)
    :sock_(sock)
    {}

    ~Connection()
    {}

    void SetHandle(func_t recv_cb,func_t send_cb,except_fun except_fun)
    {
        recv_cb_=recv_cb;
        send_cb_=send_cb;
        except_cb_=except_fun;
    }

    int Sock()
    {
        return sock_;
    }

    void Appendinbuffer(string str)
    {
        inbuffer+=str;
    }

    void Appendoutbuffer(string info)
    {
        outbuffer+=info;
    }

    string& Inbuffer()
    {
        return inbuffer;
    }

    string& Outbuffer()
    {
        return outbuffer;
    }
    void SetTcp_point(weak_ptr<TcpServer>point)
    {
        tcp_ptr_=point;
    }

private:
    string inbuffer;
    string outbuffer;

public:
    func_t recv_cb_;
    func_t send_cb_;
    except_fun except_cb_;
    uint16_t port_;
    string ip_;
    weak_ptr<TcpServer> tcp_ptr_;
    int sock_;
};